package cn.gjculture.shopping.api.service.impl;

import cn.gjculture.shopping.api.dao.CommonUpdateMapper;
import cn.gjculture.shopping.api.dao.OilCardDao;
import cn.gjculture.shopping.api.entity.OilCard;
import cn.gjculture.shopping.api.service.OilCardService;
import cn.gjculture.shopping.api.util.DateUtil;
import cn.gjculture.shopping.api.util.UUIDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OilCardServiceImpl implements OilCardService {

    @Autowired
    OilCardDao oilCardDao;

    @Autowired
    CommonUpdateMapper commonUpdateMapper;

    @Override
    public OilCard queryByPhone(String phone) {
        return oilCardDao.queryByPhone(phone);
    }

    @Override
    public int insert(OilCard oilCard) {
        oilCard.setOilCardId(UUIDUtil.getUUID());
        oilCard.setUpdateTime(DateUtil.getTimestamp());
        oilCard.setInsertTime(DateUtil.getTimestamp());
        oilCard.setStatus(1);
        return oilCardDao.insert(oilCard);
    }

    @Override
    public OilCard queryByCardNo(String cardNo) {
        return oilCardDao.queryByCardNo(cardNo);
    }

    @Override
    public List<OilCard> query() {
        return oilCardDao.query();
    }

    @Override
    public int delete(String oilCardId) {
        return oilCardDao.delete(oilCardId);
    }

    @Override
    public int update(OilCard oilCard) {
        oilCard.setUpdateTime(DateUtil.getTimestamp());
        return commonUpdateMapper.updateOilCard(oilCard);
    }
}
